---
title: "Replication Code for the Online Appendix to Partisan Hacks? How Election Cases Divide the Supreme Court"
author: "Albert H. Rivero^[Assistant Professor of Politics and John L. Nau III Assistant Professor of the History and Principles of Democracy, University of Virginia.]"
date: ""
output: 
  pdf_document:
    fig_caption: yes
    fig_crop: false
    citation_package: natbib
    keep_tex: false
    number_sections: true
fontsize: 12pt
documentclass: article
clean: true
---

```{r, include = FALSE}

library(broom)
library(rms)
library(tidyverse)
library(clubSandwich)
library(lmtest)
library(ggeffects)
library(stargazer)
library(ggpubr)
library(lubridate)
library(xtable)
library(lfe)
library(patchwork)


scdb <- read_rds("rivero_partisan_replication.rds")

scdb_warren <- scdb %>% filter(chief == "Warren", ! is.na(early.salience.est))
scdb_burger <- scdb %>% filter(chief == "Burger", ! is.na(early.salience.est))
scdb_rehnquist <- scdb %>% filter(chief == "Rehnquist", ! is.na(early.salience.est))
scdb_warren_nosal <- scdb %>% filter(chief == "Warren")
scdb_burger_nosal <- scdb %>% filter(chief == "Burger")
scdb_rehnquist_nosal <- scdb %>% filter(chief == "Rehnquist")
scdb_roberts <- scdb %>% filter(chief == "Roberts")


# lrm: issueArea factor
scdb <- scdb %>% mutate(issueArea = factor(issueArea))
scdb_warren <- scdb_warren %>% mutate(issueArea = factor(issueArea))
scdb_burger <- scdb_burger %>% mutate(issueArea = factor(issueArea))
scdb_rehnquist <- scdb_rehnquist %>% mutate(issueArea = factor(issueArea))
scdb_roberts <- scdb_roberts %>% mutate(issueArea = factor(issueArea))
```

\newcommand{\beginsupplement}{
  \setcounter{table}{0}  
  \renewcommand{\thetable}{A-\arabic{table}} 
  \setcounter{figure}{0} 
  \renewcommand{\thefigure}{A-\arabic{figure}}
}
\beginsupplement
\renewcommand{\thepage}{A -- \arabic{page}}

\section{Additional Tables and Figures}

```{r partisan_issues, echo = FALSE, fig.cap={"\\label{issue_area}Partisan-conforming voting by issue area in the non-election cases"}}

# Check which issueAreas are partisan

issueArea1 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 1, treatment == 0)), conf.int = TRUE)
issueArea1 <- issueArea1 %>% 
  mutate(issueArea = "Criminal Procedure")

issueArea2 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 2, treatment == 0)), conf.int = TRUE)
issueArea2 <- issueArea2 %>% 
  mutate(issueArea = "Civil Rights")

issueArea3 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 3, treatment == 0)), conf.int = TRUE)
issueArea3 <- issueArea3 %>% 
  mutate(issueArea = "First Amendment")

issueArea4 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 4, treatment == 0)), conf.int = TRUE)
issueArea4 <- issueArea4 %>% 
  mutate(issueArea = "Due Process")

issueArea5 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 5, treatment == 0)), conf.int = TRUE)
issueArea5 <- issueArea5 %>% 
  mutate(issueArea = "Privacy")

issueArea6 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 6, treatment == 0)), conf.int = TRUE)
issueArea6 <- issueArea6 %>% 
  mutate(issueArea = "Attorneys")

issueArea7 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 7, treatment == 0)), conf.int = TRUE)
issueArea7 <- issueArea7 %>% 
  mutate(issueArea = "Unions")

issueArea8 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 8, treatment == 0)), conf.int = TRUE)
issueArea8 <- issueArea8 %>% 
  mutate(issueArea = "Economic Activity")

issueArea9 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 9, treatment == 0)), conf.int = TRUE)
issueArea9 <- issueArea9 %>% 
  mutate(issueArea = "Judicial Power")

issueArea10 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 10, treatment == 0)), conf.int = TRUE)
issueArea10 <- issueArea10 %>% 
  mutate(issueArea = "Federalism")

issueArea12 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 12, treatment == 0)), conf.int = TRUE)
issueArea12 <- issueArea12 %>% 
  mutate(issueArea = "Federal Taxation")

issueArea13 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 13, treatment == 0)), conf.int = TRUE)
issueArea13 <- issueArea13 %>% 
  mutate(issueArea = "Miscellaneous")

issueArea14 <- tidy(lm(conforming_vote ~ 1, data = scdb %>% filter(issueArea == 14, treatment == 0)), conf.int = TRUE)
issueArea14 <- issueArea14 %>% 
  mutate(issueArea = "Private Action")

issueAreaTbl <- issueArea1 %>%
  bind_rows(issueArea2) %>%
  bind_rows(issueArea3) %>%
  bind_rows(issueArea4) %>%
  bind_rows(issueArea5) %>% 
  bind_rows(issueArea6) %>% 
  bind_rows(issueArea7) %>% 
  bind_rows(issueArea8) %>% 
  bind_rows(issueArea9) %>% 
  bind_rows(issueArea10) %>% 
  bind_rows(issueArea12)


# Six issue areas with proportions of conforming vote greater than 0.639
issueAreaTbl %>% arrange(desc(estimate)) %>% slice(6) %>% pull(estimate)

issueAreaTbl %>%
  mutate(issueArea = factor(issueArea,
                            levels = issueAreaTbl %>% 
                              filter(term == "(Intercept)") %>%
                              arrange(estimate) %>%
                              pull(issueArea))) %>%
  filter(term == "(Intercept)") %>%
  ggplot(aes(x = issueArea, y = estimate, ymin = conf.low, ymax = conf.high)) +
  geom_hline(yintercept = 0.5, linetype = "dashed") +
  geom_point() +
  geom_linerange() +
  xlab("") +
  ylab("Proportion of Votes that are Partisan-Conforming") + 
  coord_flip() + 
  theme_minimal()


```

\clearpage


```{r justice_level, message = FALSE, echo = FALSE, fig.width = 6, fig.height = 4, fig.cap = "\\label{justice_conforming}Conforming vote proportions in non-election cases by justice"}
scdb_justices <- scdb %>% pull(justiceName) %>% unique() %>% sort()

justice_ests <- vector()
justice_conf.low <- vector()
justice_conf.high <- vector()

for (i in 1:length(scdb_justices)) {
  justice_reg <- lm(conforming_vote ~ 1, data = scdb %>% filter(treatment == 0, justiceName == scdb_justices[i])) %>% tidy(conf.int = TRUE)
  justice_ests[i] <- justice_reg %>% filter(term == "(Intercept)") %>% pull(estimate)
  justice_conf.low[i] <- justice_reg %>% filter(term == "(Intercept)") %>% pull(conf.low)
  justice_conf.high[i] <- justice_reg %>% filter(term == "(Intercept)") %>% pull(conf.high)
}

justice_tbl <- tibble(justiceName = scdb_justices,
       est = justice_ests,
       conf.low = justice_conf.low,
       conf.high = justice_conf.high)

justice_tbl %>%
    mutate(Name = justiceName,
           Name = case_when(Name == "ACBarrett" ~ "Amy Coney Barrett",
                          Name == "AFortas" ~ "Abe Fortas",
                          Name == "AJGoldberg" ~ "Arthur Goldberg",
                          Name == "AMKennedy" ~ "Anthony Kennedy",
                          Name == "AScalia" ~ "Antonin Scalia",
                          Name == "BMKavanaugh" ~ "Brett Kavanaugh",
                          Name == "BRWhite" ~ "Byron White",
                          Name == "CEWhittaker" ~ "Charles Evans Whittaker",
                          Name == "CThomas" ~ "Clarence Thomas",
                          Name == "DHSouter" ~ "David Souter",
                          Name == "EKagan" ~ "Elena Kagan",
                          Name == "EWarren" ~ "Earl Warren",
                          Name == "FFrankfurter" ~ "Felix Frankfurter",
                          Name == "FMurphy" ~ "Frank Murphy",
                          Name == "FMVinson" ~ "Fred M. Vinson",
                          Name == "HABlackmun" ~ "Harry Blackmun",
                          Name == "HHBurton" ~ "Harold Burton",
                          Name == "HLBlack" ~ "Hugo Black",
                          Name == "JHarlan2" ~ "John Marshall Harlan II",
                          Name == "JPStevens" ~ "John Paul Stevens",
                          Name == "JGRoberts" ~ "John Roberts",
                          Name == "KBJackson" ~ "Ketanji Brown Jackson",
                          Name == "LFPowell" ~ "Lewis F. Powell, Jr.",
                          Name == "NMGorsuch" ~ "Neil Gorsuch",
                          Name == "PStewart" ~ "Potter Stewart",
                          Name == "RBGinsburg" ~ "Ruth Bader Ginsburg",
                          Name == "RHJackson" ~ "Robert Jackson",
                          Name == "SAAlito" ~ "Samuel Alito",
                          Name == "SDOConnor" ~ "Sandra Day O'Connor",
                          Name == "SFReed" ~ "Stanley Forman Reed",
                          Name == "SGBreyer" ~ "Stephen Breyer",
                          Name == "SMinton" ~ "Sherman Minton",
                          Name == "SSotomayor" ~ "Sonia Sotomayor",
                          Name == "TCClark" ~ "Tom C. Clark",
                          Name == "TMarshall" ~ "Thurgood Marshall",
                          Name == "WBRutledge" ~ "Wiley B. Rutledge",
                          Name == "WEBurger" ~ "Warren Burger",
                          Name == "WHRehnquist" ~ "William Rehnquist",
                          Name == "WJBrennan" ~ "William Brennan",
                          Name == "WODouglas" ~ "William O. Douglas",
                          TRUE ~ Name),
         Name = fct_reorder(Name, est)) %>%
  ggplot(aes(x = Name, y = est, ymin = conf.low, ymax = conf.high)) +
  geom_point() +
  geom_linerange() +
  geom_hline(yintercept = 0.5, linetype = "dashed") +
  xlab("") + 
  ylab("Conforming Voting Proportion") +
  coord_flip() +
  theme_minimal()
```

\clearpage


```{r more_mods_r, echo = FALSE, results = "asis"}

glm_all_origR <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct, data = scdb, x = TRUE, y = TRUE, maxit = 1000)
glm_allR <- robcov(glm_all_origR, cluster = scdb$caseId)

glm_warr_origR <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct, data = scdb_warren_nosal, x = TRUE, y = TRUE, maxit = 1000)
glm_warrR <- robcov(glm_warr_origR, cluster = scdb_warren_nosal$caseId)

glm_burg_origR <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct, data = scdb_burger_nosal, x = TRUE, y = TRUE, maxit = 1000)
glm_burgR <- robcov(glm_burg_origR, cluster = scdb_burger_nosal$caseId)

glm_rehn_origR <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct, data = scdb_rehnquist_nosal, x = TRUE, y = TRUE, maxit = 1000)
glm_rehnR <- robcov(glm_rehn_origR, cluster = scdb_rehnquist_nosal$caseId)

glm_rob_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + treatment_fct, data = scdb_roberts, x = TRUE, y = TRUE, maxit = 1000)
glm_rob <- robcov(glm_rob_orig, scdb_roberts$caseId)


stargazer(glm_allR, glm_warrR, glm_burgR, glm_rehnR, glm_rob,
          keep = c("lc_alignment",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "polarized_issue",
                   "us_as_party",
                   "treatment_fct",
                   "Constant"),
                    keep.stat = c("n", "ll"),
          covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "Civil Rights/Liberties",
                               "U.S. as Party",
                               "Election Law Case",
                               "Constant"),
          digits = 2,
          label = "reg_roberts",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the election law category, with same controls as the Roberts model; standard errors clustered by case",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote",
          style = "APSR",
          header = FALSE)
```


```{r all_salience, echo = FALSE, results = "asis"}
glm_all_sal_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est+ treatment_fct, data = scdb %>% filter(! is.na(early.salience.est)), x = TRUE, y = TRUE, maxit = 1000)
glm_all_sal <- robcov(glm_all_sal_orig, cluster = scdb %>% filter(! is.na(early.salience.est)) %>% pull(caseId))

stargazer(glm_all_sal,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "polarized_issue",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Constant"),
                              covariate.labels = c("Republican Justice", 
                              "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "Civil Rights/Liberties",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Constant"),
                    keep.stat = c("n", "adj.rsq"),
          digits = 2,
          label = "reg_sal",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the election law category, with controls, including case salience; standard errors clustered by case",
          column.labels = c("All Cases"),
          dep.var.labels = "Conforming vote",
          style = "APSR",
          header = FALSE)
```


```{r roberts_warren_split, echo = FALSE, results = "asis"}
glm_warr_origALT1 <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + early.salience.est+ treatment_fct, data = scdb_warren %>% filter(naturalCourt < 1408), x = TRUE, y = TRUE, maxit = 1000)
glm_warrALT1 <- robcov(glm_warr_origALT1, scdb_warren %>% filter(naturalCourt < 1408) %>% pull(caseId))

glm_warr_origALT2 <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + early.salience.est+ treatment_fct, data = scdb_warren %>% filter(naturalCourt >= 1408), x = TRUE, y = TRUE, maxit = 1000)
glm_warrALT2 <- robcov(glm_warr_origALT2, scdb_warren %>% filter(naturalCourt >= 1408) %>% pull(caseId))

glm_rob_origALT1 <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + treatment_fct, data = scdb_roberts %>% filter(naturalCourt < 1706), x = TRUE, y = TRUE, maxit = 1000)
glm_robALT1 <- robcov(glm_rob_origALT1, scdb_roberts %>% filter(naturalCourt < 1706) %>% pull(caseId))

glm_rob_origALT2 <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + treatment_fct, data = scdb_roberts %>% filter(naturalCourt >= 1706), x = TRUE, y = TRUE, maxit = 1000)
glm_robALT2 <- robcov(glm_rob_origALT2, scdb_roberts %>% filter(naturalCourt >= 1706) %>% pull(caseId))


stargazer(glm_warrALT1, glm_warrALT2, glm_robALT1, glm_robALT2,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "polarized_issue",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Constant"),
                    keep.stat = c("n", "ll"),
          covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "Civil Rights/Liberties",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Constant"),
          digits = 2,
          label = "reg_warr_rob",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the election law category, with controls; standard errors clustered by case",
          column.labels = c("Warren ", "Warren", "Roberts", "Roberts \\\\ & Pre-Goldberg & Post-Goldberg & Pre-Gorsuch & Post-Gorsuch"),
          dep.var.labels = "Conforming vote",
          style = "APSR",
          header = FALSE)
```

\clearpage

```{r glms_plot_spec, echo = FALSE, message = FALSE, warning = FALSE, fig.width = 7.5, fig.height = 3.75, out.width = "95%", fig.align = "center", fig.cap = "\\label{glm_preds_spec}Predicted probabilities of conforming votes for election law and non-election cases, by Chief Justice, covariates held at specified values"}

plot_conditions <- scdb %>% select(republican_pid, lc_alignment, on_appeal, conflict_case, lc_disagreement, lc_vertical_dis, judicial_review, polarized_issue, us_as_party, early.salience.est) %>% apply(MARGIN = 2, FUN = median, na.rm=T)
plot_conditions_rob <- scdb %>% select(republican_pid, lc_alignment, conflict_case, lc_disagreement, lc_vertical_dis, judicial_review, polarized_issue, us_as_party) %>% apply(MARGIN = 2, FUN = median, na.rm=T)


# Salience estimate median
plot_conditions["early.salience.est"]

glm_warr_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est+ treatment_fct, data = scdb_warren, x = TRUE, y = TRUE, maxit = 1000)
glm_warr <- robcov(glm_warr_orig, cluster = scdb_warren$caseId)

glm_burg_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est+ treatment_fct, data = scdb_burger, x = TRUE, y = TRUE, maxit = 1000)
glm_burg <- robcov(glm_burg_orig, cluster = scdb_burger$caseId)

glm_rehn_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est + treatment_fct, data = scdb_rehnquist, x = TRUE, y = TRUE, maxit = 1000)
glm_rehn <- robcov(glm_rehn_orig, cluster = scdb_rehnquist$caseId)

plot1a <- ggpredict(glm_warr, terms = "treatment_fct", condition = plot_conditions) %>%
  plot() + ylim(c(0.52, 1)) + ggtitle("Warren") + xlab("") + ylab("Conforming Vote")
plot2a <- ggpredict(glm_burg, terms = "treatment_fct", condition = plot_conditions) %>%
  plot() + ylim(c(0.52, 1)) + ggtitle("Burger") + xlab("") + ylab("")
plot3a <- ggpredict(glm_rehn, terms = "treatment_fct", condition = plot_conditions) %>%
  plot() + ylim(c(0.52, 1)) + ggtitle("Rehnquist") + xlab("") + ylab("")
plot4a <- ggpredict(glm_rob, terms = "treatment_fct", condition = plot_conditions_rob) %>%
  plot() + ylim(c(0.52, 1)) + ggtitle("Roberts") + xlab("") + ylab("")

# Predicted probability, non-election cases, Roberts model
ggpredict(glm_rob, terms = "treatment_fct", condition = plot_conditions_rob) %>% as_tibble() %>% filter(x == "Non-election") %>% pull(predicted)

plot1a + plot2a + plot3a + plot4a + plot_layout(nrow = 1)
```

```{r roberts_plot_spec, echo = FALSE, message = FALSE, warning = FALSE, fig.width = 3.75, fig.height = 3.75, fig.align = "center", fig.cap = "\\label{gorsuch_spec}Predicted probabilities of conforming votes for election law and non-election cases, by Roberts Court era (pre- and post-Gorsuch), covariates held at specified values"}



plotROBALT1a <- ggpredict(glm_robALT1, terms = "treatment_fct", condition = plot_conditions_rob) %>% 
  plot() + ylim(c(0.52, 1)) + ggtitle("Pre-Gorsuch") + xlab("") + ylab("Conforming Vote")
plotROBALT2a <- ggpredict(glm_robALT2, terms = "treatment_fct", condition = plot_conditions_rob) %>% 
  plot() + ylim(c(0.52, 1)) + ggtitle("Post-Gorsuch") + xlab("") + ylab("")

plotROBALT1a + plotROBALT2a + plot_layout(nrow = 1)
```

```{r warren_plot, echo = FALSE, message = FALSE, warning = FALSE, fig.width = 3.75, fig.height = 3.75, fig.align = "center", fig.cap = "\\label{goldberg}Predicted probabilities of conforming votes for election law and non-election cases, by Warren Court era (pre- and post-Goldberg)"}

plotWARRALT1 <- predict_response(glm_warrALT1, terms = "treatment_fct", margin = "empirical") %>%
  plot() + ylim(c(0.49, 1)) + ggtitle("Pre-Goldberg") + xlab("") + ylab("Conforming Vote")
plotWARRALT2 <- predict_response(glm_warrALT2, terms = "treatment_fct", margin = "empirical") %>%
  plot() + ylim(c(0.49, 1)) + ggtitle("Post-Goldberg") + xlab("") + ylab("")

plotWARRALT1 + plotWARRALT2 + plot_layout(nrow = 1)
```

```{r warren_plot_spec, echo = FALSE, message = FALSE, warning = FALSE, fig.width = 3.75, fig.height = 3.75, fig.align = "center", fig.cap = "\\label{goldberg_spec}Predicted probabilities of conforming votes for election law and non-election cases, by Warren Court era (pre- and post-Goldberg), covariates held at specified values"}

plotWARRALT1a <- ggpredict(glm_warrALT1, terms = "treatment_fct", condition = plot_conditions) %>%
  plot() + ylim(c(0.49, 1)) + ggtitle("Pre-Goldberg") + xlab("") + ylab("Conforming Vote")
plotWARRALT2a <- ggpredict(glm_warrALT2, terms = "treatment_fct", condition = plot_conditions) %>%
  plot() + ylim(c(0.49, 1)) + ggtitle("Post-Goldberg") + xlab("") + ylab("")

plotWARRALT1a + plotWARRALT2a + plot_layout(nrow = 1)
```



\clearpage

```{r over_time_agenda, echo = FALSE, fig.cap = "\\label{over-time-agenda}Share of cases by era that are on civil rights/civil liberties and with unaligned lower court rulings (left panel) and proportion of conforming votes in such cases (right panel)"}
share_unaligned_polarized <- scdb %>%
  group_by(caseId) %>%
  slice(1) %>%
  ungroup() %>%
  mutate(polarized_issue_unaligned = ifelse(polarized_issue == 1 & lc_alignment == 0, 1, 0),
         unpolarized_issue_aligned = ifelse(polarized_issue == 0 & lc_alignment == 1, 1, 0),
         court_era = case_when(chief == "Warren" & naturalCourt < 1408 ~ "Warren, Pre-Goldberg",
                               chief == "Warren" & naturalCourt >= 1408 ~ "Warren, Post-Goldberg",
                               chief == "Burger" ~ "Burger",
                               chief == "Rehnquist" ~ "Rehnquist",
                               chief == "Roberts" & naturalCourt < 1706 ~ "Roberts, Pre-Gorsuch",
                               chief == "Roberts" & naturalCourt >= 1706 ~ "Roberts, Post-Gorsuch"),
         court_era = factor(court_era,
                               levels = c("Warren, Pre-Goldberg",
                                          "Warren, Post-Goldberg",
                                          "Burger",
                                          "Rehnquist",
                                          "Roberts, Pre-Gorsuch",
                                          "Roberts, Post-Gorsuch"))) %>%
  group_by(court_era) %>%
  summarize(polarized_issue_unaligned_lb = t.test(polarized_issue_unaligned)$conf.int[1],
            polarized_issue_unaligned_ub = t.test(polarized_issue_unaligned)$conf.int[2],
            polarized_issue_unaligned = mean(polarized_issue_unaligned),
            unpolarized_issue_aligned = mean(unpolarized_issue_aligned),
            .groups = "drop") %>%
  ggplot(aes(x = court_era, y = polarized_issue_unaligned, 
             ymin = polarized_issue_unaligned_lb, ymax = polarized_issue_unaligned_ub)) +
  geom_point() +
  geom_linerange() +
  ylab("Lower Court Unaligned and Civil Rights/Liberties Issue") +
  xlab("") +
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))

conforming_unaligned_polarized <- scdb %>%
  mutate(polarized_issue_unaligned = ifelse(polarized_issue == 1 & lc_alignment == 0, 1, 0),
         unpolarized_issue_aligned = ifelse(polarized_issue == 0 & lc_alignment == 1, 1, 0),
         court_era = case_when(chief == "Warren" & naturalCourt < 1408 ~ "Warren, Pre-Goldberg",
                               chief == "Warren" & naturalCourt >= 1408 ~ "Warren, Post-Goldberg",
                               chief == "Burger" ~ "Burger",
                               chief == "Rehnquist" ~ "Rehnquist",
                               chief == "Roberts" & naturalCourt < 1706 ~ "Roberts, Pre-Gorsuch",
                               chief == "Roberts" & naturalCourt >= 1706 ~ "Roberts, Post-Gorsuch"),
         court_era = factor(court_era,
                            levels = c("Warren, Pre-Goldberg",
                                       "Warren, Post-Goldberg",
                                       "Burger",
                                       "Rehnquist",
                                       "Roberts, Pre-Gorsuch",
                                       "Roberts, Post-Gorsuch"))) %>%
  filter(polarized_issue_unaligned == 1) %>%
  group_by(court_era) %>%
  summarize(conforming_vote_lb = t.test(conforming_vote)$conf.int[1],
            conforming_vote_ub = t.test(conforming_vote)$conf.int[2],
            conforming_vote = mean(conforming_vote),
            .groups = "drop") %>%
  ggplot(aes(x = court_era, y = conforming_vote, ymin = conforming_vote_lb, ymax = conforming_vote_ub)) +
  geom_point() +
  geom_linerange() +
  ylab("Conforming Vote") +
  xlab("") +
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))

share_unaligned_polarized + conforming_unaligned_polarized
```

```{r more_modsE, echo = FALSE, results = "asis"}

glm_all_origE <- lrm(conforming_vote ~ ideo_extreme + republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct, data = scdb, x = TRUE, y = TRUE, maxit = 1000)
glm_allE <- robcov(glm_all_origE, cluster = scdb$caseId)

glm_warr_origE <- lrm(conforming_vote ~ ideo_extreme + republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est + treatment_fct, data = scdb_warren, x = TRUE, y = TRUE, maxit = 1000)
glm_warrE <- robcov(glm_warr_origE, cluster = scdb_warren$caseId)

glm_burg_origE <- lrm(conforming_vote ~ ideo_extreme + republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est + treatment_fct, data = scdb_burger, x = TRUE, y = TRUE, maxit = 1000)
glm_burgE <- robcov(glm_burg_origE, cluster = scdb_burger$caseId)

glm_rehn_origE <- lrm(conforming_vote ~ ideo_extreme + republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party +  early.salience.est + treatment_fct, data = scdb_rehnquist, x = TRUE, y = TRUE, maxit = 1000)
glm_rehnE <- robcov(glm_rehn_origE, cluster = scdb_rehnquist$caseId)

glm_rob_origE <- lrm(conforming_vote ~ ideo_extreme + republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + treatment_fct, data = scdb_roberts, x = TRUE, y = TRUE, maxit = 1000)
glm_robE <- robcov(glm_rob_origE, scdb_roberts$caseId)

stargazer(glm_allE, glm_warrE, glm_burgE, glm_rehnE, glm_robE,
          keep = c("ideo_extreme",
                   "lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "polarized_issue",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Constant"),
                    keep.stat = c("n", "ll"),
          covariate.labels = c("Ideological extremity",
                               "Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "Civil Rights/Liberties",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Constant"),
          digits = 2,
          label = "reg_extreme",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the election law category, with controls, including ideological extremity; standard errors clustered by case",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote",
          style = "APSR",
          header = FALSE)
```

```{r more_mods_pres, echo = FALSE, results = "asis"}

glm_all_orig2 <- lrm(conforming_vote_pres ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct, data = scdb, x = TRUE, y = TRUE, maxit = 1000)
glm_all2 <- robcov(glm_all_orig2, cluster = scdb$caseId)

glm_warr_orig2 <- lrm(conforming_vote_pres ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est + treatment_fct, data = scdb_warren, x = TRUE, y = TRUE, maxit = 1000)
glm_warr2 <- robcov(glm_warr_orig2, cluster = scdb_warren$caseId)

glm_burg_orig2 <- lrm(conforming_vote_pres ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est + treatment_fct, data = scdb_burger, x = TRUE, y = TRUE, maxit = 1000)
glm_burg2 <- robcov(glm_burg_orig2, cluster = scdb_burger$caseId)

glm_rehn_orig2 <- lrm(conforming_vote_pres ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party +  early.salience.est + treatment_fct, data = scdb_rehnquist, x = TRUE, y = TRUE, maxit = 1000)
glm_rehn2 <- robcov(glm_rehn_orig2, cluster = scdb_rehnquist$caseId)

glm_rob_orig2 <- lrm(conforming_vote_pres ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + treatment_fct, data = scdb_roberts, x = TRUE, y = TRUE, maxit = 1000)
glm_rob2 <- robcov(glm_rob_orig2, scdb_roberts$caseId)


stargazer(glm_all2, glm_warr2, glm_burg2, glm_rehn2, glm_rob2,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "polarized_issue",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Constant"),
                    keep.stat = c("n", "ll"),
          covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "Civil Rights/Liberties",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Constant"),
          digits = 2,
          label = "reg_presparty",
          title = "Logistic regressions predicting partisanship-conforming votes (using appointing president partisanship) with whether a case falls into the election law category, with controls; standard errors clustered by case",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote} \\\\ & \\multicolumn{5}{c}{(Appointing president partisanship)",
          style = "APSR",
          header = FALSE)
```

```{r yet_more_mods_pres, echo = FALSE, results = "asis"}

glm_all_orig3 <- lrm(conforming_vote_at_appt ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct, data = scdb, x = TRUE, y = TRUE, maxit = 1000)
glm_all3 <- robcov(glm_all_orig3, cluster = scdb$caseId)

glm_warr_orig3 <- lrm(conforming_vote_at_appt ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est + treatment_fct, data = scdb_warren, x = TRUE, y = TRUE, maxit = 1000)
glm_warr3 <- robcov(glm_warr_orig3, cluster = scdb_warren$caseId)

glm_burg_orig3 <- lrm(conforming_vote_at_appt ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est + treatment_fct, data = scdb_burger, x = TRUE, y = TRUE, maxit = 1000)
glm_burg3 <- robcov(glm_burg_orig3, cluster = scdb_burger$caseId)

glm_rehn_orig3 <- lrm(conforming_vote_at_appt ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party +  early.salience.est + treatment_fct, data = scdb_rehnquist, x = TRUE, y = TRUE, maxit = 1000)
glm_rehn3 <- robcov(glm_rehn_orig3, cluster = scdb_rehnquist$caseId)

glm_rob_orig3 <- lrm(conforming_vote_at_appt ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + treatment_fct, data = scdb_roberts, x = TRUE, y = TRUE, maxit = 1000)
glm_rob3 <- robcov(glm_rob_orig3, scdb_roberts$caseId)


stargazer(glm_all3, glm_warr3, glm_burg3, glm_rehn3, glm_rob3,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "polarized_issue",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Constant"),
                    keep.stat = c("n", "ll"),
          covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "Civil Rights/Liberties",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Constant"),
          digits = 2,
          label = "reg3",
          title = "Logistic regressions predicting partisanship-conforming votes (using self-described partisanship at the time of appointment) with whether a case falls into the election law category, with controls; standard errors clustered by case",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote} \\\\ & \\multicolumn{5}{c}{(Self-described partisanship at appointment)",
          style = "APSR",
          header = FALSE)
```






```{r more_mods_is, echo = FALSE, results = "asis"}

glm_all_is_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + issueArea + us_as_party + treatment_fct, data = scdb, x = TRUE, y = TRUE, maxit = 1000)
glm_all_is <- robcov(glm_all_is_orig, cluster = scdb$caseId)

glm_warr_is_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + issueArea + us_as_party + early.salience.est+ treatment_fct + treatment_fct, data = scdb_warren, x = TRUE, y = TRUE, maxit = 1000)
glm_warr_is <- robcov(glm_warr_is_orig, cluster = scdb_warren$caseId)

glm_burg_is_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + issueArea + us_as_party + early.salience.est+ treatment_fct + treatment_fct, data = scdb_burger, x = TRUE, y = TRUE, maxit = 1000)
glm_burg_is <- robcov(glm_burg_is_orig, cluster = scdb_burger$caseId)

glm_rehn_is_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + issueArea + us_as_party + early.salience.est + treatment_fct, data = scdb_rehnquist, x = TRUE, y = TRUE, maxit = 1000)
glm_rehn_is <- robcov(glm_rehn_is_orig, cluster = scdb_rehnquist$caseId)

glm_rob_is_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + issueArea + us_as_party + treatment_fct, data = scdb_roberts, x = TRUE, y = TRUE, maxit = 1000)
glm_rob_is <- robcov(glm_rob_is_orig, scdb_roberts$caseId)

stargazer(glm_all_is, glm_warr_is, glm_burg_is, glm_rehn_is, glm_rob_is,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Constant"),
                    keep.stat = c("n", "ll"),
          covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Constant"),
          digits = 2,
          label = "reg_is",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the election law category, with controls and issue area fixed effects; standard errors clustered by case",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote",
          add.lines = list(c("Issue Area FEs", "\\checkmark",  "\\checkmark",  "\\checkmark",  "\\checkmark",  "\\checkmark")),
          style = "APSR",
          header = FALSE)
```


```{r limit_mods, echo = FALSE, results = "asis"}
# Limit to polarized_issue

# all
pol_all <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + treatment_fct,
    data = scdb %>% filter(polarized_issue == 1), x = TRUE, y = TRUE, maxit = 1000) %>% 
  robcov(cluster = scdb %>% filter(polarized_issue == 1) %>% pull(caseId))
# warren
pol_war <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + early.salience.est+ treatment_fct,
    data = scdb_warren %>% filter(polarized_issue == 1), x = TRUE, y = TRUE, maxit = 1000) %>% 
  robcov(cluster = scdb_warren %>% filter(polarized_issue == 1) %>% pull(caseId))
# burger
pol_bur <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + early.salience.est+ treatment_fct,
    data = scdb_burger %>% filter(polarized_issue == 1), x = TRUE, y = TRUE, maxit = 1000) %>% 
  robcov(cluster = scdb_burger %>% filter(polarized_issue == 1) %>% pull(caseId))
# rehnquist
pol_reh <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + early.salience.est+ treatment_fct,
    data = scdb_rehnquist %>% filter(polarized_issue == 1), x = TRUE, y = TRUE, maxit = 1000) %>% robcov(cluster = scdb_rehnquist %>% filter(polarized_issue == 1) %>% pull(caseId))
# roberts
pol_rob <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + treatment_fct,
    data = scdb_roberts %>% filter(polarized_issue == 1), x = TRUE, y = TRUE, maxit = 1000) %>% robcov(cluster = scdb_roberts %>% filter(polarized_issue == 1) %>% pull(caseId))

# Limit to issueArea %in% c(2,3)

# all
lim_all <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + treatment_fct,
    data = scdb %>% filter(issueArea %in% c(2,3)), x = TRUE, y = TRUE, maxit = 1000) %>% 
  robcov(cluster = scdb %>% filter(issueArea %in% c(2,3)) %>% pull(caseId))
# warren
lim_war <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + early.salience.est+ treatment_fct,
    data = scdb_warren %>% filter(issueArea %in% c(2,3)), x = TRUE, y = TRUE, maxit = 1000) %>% 
  robcov(cluster = scdb_warren %>% filter(issueArea %in% c(2,3)) %>% pull(caseId))
# burger
lim_bur <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + early.salience.est+ treatment_fct,
    data = scdb_burger %>% filter(issueArea %in% c(2,3)), x = TRUE, y = TRUE, maxit = 1000) %>% 
  robcov(cluster = scdb_burger %>% filter(issueArea %in% c(2,3)) %>% pull(caseId))
# rehnquist
lim_reh <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + early.salience.est+ treatment_fct,
    data = scdb_rehnquist %>% filter(issueArea %in% c(2,3)), x = TRUE, y = TRUE, maxit = 1000) %>% 
  robcov(cluster = scdb_rehnquist %>% filter(issueArea %in% c(2,3)) %>% pull(caseId))
# roberts
lim_rob <- lrm(conforming_vote ~ republican_pid + lc_alignment + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + us_as_party + treatment_fct,
    data = scdb_roberts %>% filter(issueArea %in% c(2,3)), x = TRUE, y = TRUE, maxit = 1000) %>% 
  robcov(cluster = scdb_roberts %>% filter(issueArea %in% c(2,3)) %>% pull(caseId))

stargazer(pol_all, pol_war, pol_bur, pol_reh, pol_rob,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Constant"),
                    keep.stat = c("n", "ll"),
          covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Constant"),
          digits = 2,
          label = "reg_pol",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the election law category, with controls; standard errors clustered by case. Data limited to civil rights/civil liberties.",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote",
          style = "APSR",
          header = FALSE)

stargazer(lim_all, lim_war, lim_bur, lim_reh, lim_rob,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Constant"),
                    keep.stat = c("n", "ll"),
          covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Constant"),
          digits = 2,
          label = "reg_lim",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the election law category, with controls; standard errors clustered by case. Data limited to civil rights and First Amendment cases.",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote",
          style = "APSR",
          header = FALSE)
```

```{r search_seizure, echo = FALSE, results = "asis"}
# Search and seizure
search_all <- scdb %>%
  mutate(search_treatment = ifelse(issue %in% 10050:10070, "Search and seizure", "Non-search and seizure"),
         search_treatment = factor(search_treatment, levels = c("Non-search and seizure", "Search and seizure"))) %>%
  filter(polarized_issue == 1)
search_warren <- scdb_warren %>%
  mutate(search_treatment = ifelse(issue %in% 10050:10070, "Search and seizure", "Non-search and seizure"),
         search_treatment = factor(search_treatment, levels = c("Non-search and seizure", "Search and seizure"))) %>%
  filter(polarized_issue == 1)
search_burger <- scdb_burger %>%
  mutate(search_treatment = ifelse(issue %in% 10050:10070, "Search and seizure", "Non-search and seizure"),
         search_treatment = factor(search_treatment, levels = c("Non-search and seizure", "Search and seizure"))) %>%
  filter(polarized_issue == 1)
search_rehnquist <- scdb_rehnquist %>%
  mutate(search_treatment = ifelse(issue %in% 10050:10070, "Search and seizure", "Non-search and seizure"),
         search_treatment = factor(search_treatment, levels = c("Non-search and seizure", "Search and seizure"))) %>%
  filter(polarized_issue == 1)
search_roberts <- scdb_roberts %>%
  mutate(search_treatment = ifelse(issue %in% 10050:10070, "Search and seizure", "Non-search and seizure"),
         search_treatment = factor(search_treatment, levels = c("Non-search and seizure", "Search and seizure"))) %>%
  filter(polarized_issue == 1)

search1 <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + us_as_party + search_treatment, 
    data = search_all, x = TRUE, y = TRUE, maxit = 1000) %>% robcov(cluster = search_all$caseId)
search2 <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + us_as_party + early.salience.est + search_treatment,
    data = search_warren, x = TRUE, y = TRUE, maxit = 1000) %>% robcov(cluster = search_warren$caseId)
search3 <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + us_as_party + early.salience.est + search_treatment,
    data = search_burger, x = TRUE, y = TRUE, maxit = 1000) %>% robcov(cluster = search_burger$caseId)
search4 <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + us_as_party + early.salience.est + search_treatment,
    data = search_rehnquist, x = TRUE, y = TRUE, maxit = 1000) %>% robcov(cluster = search_rehnquist$caseId)
search5 <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + us_as_party + search_treatment,
    data = search_roberts, x = TRUE, y = TRUE, maxit = 1000) %>% robcov(cluster= search_roberts$caseId)

stargazer(search1, search2, search3, search4, search5,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "us_as_party",
                   "early.salience.est",
                   "search_treatment",
                   "Constant"),
          covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Search and Seizure Case",
                               "Constant"),
          keep.stat = c("n", "ll"),
          digits = 2,
          label = "reg_search",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the search and seizure category (SCDB issue codes 10050-10070), with controls; standard errors clustered by case",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote",
          style = "APSR",
          header = FALSE)
```


```{r election_year_table, echo = FALSE, results = "asis"}

# Interact with year of a presidential election, overall

all2_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct * `Presidential election year`, data = scdb, x = TRUE, y = TRUE, maxit = 1000)
all2 <- robcov(all2_orig, cluster = scdb$caseId)

# Interact with year of a presidential election, by chief

warr2_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review + polarized_issue + us_as_party + early.salience.est+ treatment_fct * `Presidential election year`, data = scdb_warren, x = TRUE, y = TRUE, maxit = 1000)
warr2 <- robcov(warr2_orig, cluster = scdb_warren$caseId)

burg2_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est+ treatment_fct * `Presidential election year`, data = scdb_burger, x = TRUE, y = TRUE, maxit = 1000)
burg2 <- robcov(burg2_orig, cluster = scdb_burger$caseId)

rehn2_orig <- lrm(conforming_vote ~ republican_pid + lc_alignment + on_appeal + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + early.salience.est+ treatment_fct * `Presidential election year`, data = scdb_rehnquist, x = TRUE, y = TRUE, maxit = 1000)
rehn2 <- robcov(rehn2_orig, cluster = scdb_rehnquist$caseId)

rob2_orig <- lrm(conforming_vote ~ republican_pid  + conflict_case + lc_disagreement + lc_vertical_dis + judicial_review  + polarized_issue + us_as_party + treatment_fct * `Presidential election year`, data = scdb_roberts, x = TRUE, y = TRUE, maxit = 1000)
rob2 <- robcov(rob2_orig, cluster = scdb_roberts$caseId)

stargazer(all2, warr2, burg2, rehn2, rob2,
          keep = c("lc_alignment",
                   "on_appeal",
                   "conflict_case",
                   "lc_disagreement",
                   "lc_vertical_dis",
                   "republican_pid",
                   "judicial_review",
                   "polarized_issue",
                   "us_as_party",
                   "early.salience.est",
                   "treatment_fct",
                   "Presidential election year",
                   "Constant"),
                    keep.stat = c("n", "ll"),
                    covariate.labels = c("Republican Justice",
                               "Lower Court Alignment",
                               "On Appeal",
                               "Federal Court Conflict",
                               "Lower Court Disagreement",
                               "LC Disagreement (Vertical)",
                               "Judicial Review",
                               "Civil Rights/Liberties",
                               "U.S. as Party",
                               "Early Salience Estimate",
                               "Election Law Case",
                               "Pres. Election Year",
                               "Election Law $\\times$ Election Year",
                               "Constant"),
          digits = 2,
          label = "reg_pres",
          title = "Logistic regressions predicting partisanship-conforming votes with whether a case falls into the election law category by whether a case is decided in a presidential election year; standard errors clustered by case",
          column.labels = c("All Cases", "Warren", "Burger", "Rehnquist", "Roberts"),
          dep.var.labels = "Conforming vote",
          style = "APSR",
          header = FALSE)
```

